package com.pen.interfece.controller.user;

import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.pen.interfece.service.ModelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class AskController {

    @Autowired
    private ModelService modelService;

    /**
     * 接收用户的prompt并调用ModelService来获取响应。
     *
     * @param prompt 用户输入的提示文本
     * @return ModelService的响应结果
     */
    @GetMapping("/ask")
    public String queryModel(@RequestParam String prompt) throws NoApiKeyException, InputRequiredException {

        log.info(prompt);
        log.info("问答开始");
        log.info("开始");

        return modelService.callModel(prompt);
    }
}